<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <form id="submitForm" class="well form-inline margin-top-20" method="post" action="{:url('Wechat/fansList')}">
        <!--时间:-->
        <!--<input type="text" class="form-control js-bootstrap-datetime" name="start_time"-->
        <!--value="{$start_time|default=''}"-->
        <!--style="width: 140px;" autocomplete="off">- -->
        <!--<input type="text" class="form-control js-bootstrap-datetime" name="end_time"-->
        <!--value="{$end_time|default=''}"-->
        <!--style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;-->
        关键字:
        <input type="text" class="form-control" name="keyword" style="width: 200px;"
               value="{$keyword|default=''}" placeholder="请输入关键字...">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger"  href="{:url('Wechat/fansList')}" >清空</a>

        <a class="btn btn-danger"  href="{:url('Wechat/updateFansList')}" >同步粉丝</a><br/><br/>
        <label class="form-required">若您的粉丝较多，请耐心等待，直到出现“同步完成”才是同步粉丝成功</label><br/>
        <label class="form-required">更改完备注之后，建议进行一次【同步粉丝】，防止出错</label>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-primary btn-sm" type="button" onclick="daTag()">批量打标签</button>
            <button class="btn btn-primary btn-sm" type="button" onclick="cancelTag()">批量取消标签
            </button>
        </div>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th>昵称</th>
                <th>头像</th>
                <th>备注</th>
                <th>性别</th>
                <th>所在地</th>
                <th>关注时间</th>
                <th>所属标签</th>
            </tr>
            </thead>
            <notempty name="list">
                <foreach name="list" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="openid"
                               value="{$vo.openid}" title="openid:{$vo.openid}">
                    </td>
                    <td><b>{$vo.nickname}</b></td>
                    <td><b><img src="{$vo.headimgurl}" width="50"></b></td>
                    <td><b>
                        <if condition="$vo.remark neq ''"><a href="javascript:;" class="caname">{$vo.remark}</a>
                            <else /> <a href="javascript:;" class="caname">点击备注</a>
                        </if>
                        <input type="hidden" name="openid" value="{$vo.openid}">
                    </b></td>
                    <td>
                        <switch name="$vo.sex">
                            <case value="1">男</case>
                            <case value="2">女</case>
                            <default />粉丝未填写
                        </switch>
                    </td>
                    <td>{$vo.country}&nbsp;&nbsp;{$vo.province}&nbsp;&nbsp;{$vo.city}</td>
                    <td><?php echo date("Y-m-d",$vo['subscribe_time']) ?></td>
                    <td>
                        <volist name="tag" id="voTag">
                            <?php $array=explode(',',$vo['tagid_list']); ?>
                            <if condition="in_array($voTag.tagid_list,$array)">{$voTag.name}&nbsp;&nbsp;</if>
                        </volist>
                    </td>
                </tr>
            </foreach>
            </notempty>
            <tfoot>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th>昵称</th>
                <th>头像</th>
                <th>备注</th>
                <th>性别</th>
                <th>所在地</th>
                <th>关注时间</th>
                <th>所属标签</th>
            </tr>
            </tfoot>
        </table>
        <ul class="pagination">{$page|default=''}</ul>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    function reloadPage(win) {
        win.location.reload();
    }
    $(function() {
        $(".caname").click(function() {
            var td = $(this);
            var txt = td.text();
            var input = $("<input type='text' value='' placeholder='"+txt+"'/>");
            td.html(input);
            input.click(function() { return false; });
//获取焦点
            input.trigger("focus");
//文本框失去焦点后提交内容，重新变为文本
            input.blur(function() {
                var newtxt = $(this).val();
                if(newtxt == ''){
                    td.html(txt);
                }else if(newtxt == txt){
                    td.html(txt);
                }else{
                    td.html(newtxt);
                    var openid=td.siblings().val();
                    $.ajax({
                        type: "POST",
                        url: "{:url('Wechat/changeRemark')}",
                        data: {remark:newtxt,openid:openid},
                        dataType:"json",
                        success: function(data){
                            layer.msg(data.msg);
                        }
                    });
                }
            });
        });
    });


    function daTag() {
        var str = "<div style='padding: 10px;'><notempty name='tag'><volist name='tag' id='voTag1'><label class='checkbox-inline' style='width: 8em;margin-left: 0px;'><input type='checkbox' value='{$voTag1.tagid_list}' name='tag_id'>{$voTag1.name}</label></volist></div><div style='position: absolute;left: 0;right: 0;bottom: 0;padding: 20px 30px;text-align: center;border-top: 1px solid #e7e7eb;'><button href='javascript:;' class='btn btn_primary' onclick='changetags();'>确定</button></div></notempty></div>";
        layer.open({
            type: 1,
            title:'注意：取消标签是取消所选用户的所有标签',
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '240px'], //宽高
            content: str
        });
    }
    function changetags() {
        var openid_array=new Array();
        $('input[name="openid"]:checked').each(function(){
            openid_array.push($(this).val());//向数组中添加元素
        });
        var openid=openid_array.join(',');//将数组元素连接起来以构建一个字符串

        var tagid_array=new Array();
        $('input[name="tag_id"]:checked').each(function(){
            tagid_array.push($(this).val());//向数组中添加元素
        });
        var tag_id=tagid_array.join(',');//将数组元素连接起来以构建一个字符串
        $.ajax({
            type: "POST",
            url: "{:url('wechat/daTag')}",
            data: {openid:openid,tag_id:tag_id},
            success: function(data){
                layer.msg(data.msg, {icon: data.data},function () {
                    window.location.href="{:url('Wechat/updateFansList')}";
                });
            }
        });
    }
</script>
</body>
</html>